package com.backstage.base.mapper;

import com.backstage.base.models.User;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    @Delete("DELETE FROM t_user WHERE id = ${id}")
    void deleteFromUser(@Param("id") Integer id);

    @Insert("INSERT INTO t_user(id, username, age, sex, balance, regTime,pwd) VALUES (#{id},#{username},#{age},#{sex},#{balance},#{regTime},#{pwd})")
    void insertUserRecord(@Param("id") Integer id, @Param("username") String username, @Param("age") Integer age, @Param("sex") boolean sex, @Param("balance") float balance, @Param("regTime") String regTime, @Param("pwd") String pwd);

    @Select("SELECT t_user FROM t_user WHERE id = #{id} AND username = #{username} AND age = #{age}")
    List<Integer> getUserCount(@Param("id") Integer id, @Param("username") String username, @Param("age") Integer age);

    @Select("SELECT * FROM t_user")
    public List<User> getUserList();

    @Select("SELECT * FROM t_user")
    public PageInfo<User> getUsersByPage(@Param("pageNo") Integer pageNo, @Param("pageSize") Integer pageSize);

    @Select("SELECT * FROM t_user WHERE id = #{id}")
    public User queryById(@Param("id") Integer id);

    @Select("select * from t_user where username = #{username}")
    public List<User> find(String username);

    @Update("update t_user set age=#{age}, sex=#{sex}, balance=#{balance}, username=#{username}, pwd=#{pwd},regTime=#{regTime} WHERE id=#{id}")
    void updateUser(@Param("id") Integer id,@Param("age") Integer age,@Param("sex") boolean sex,@Param("balance") float balance,@Param("username") String username,@Param("pwd") String pwd,@Param("regTime") String regTime);

    @Select("select * from t_user where pwd = #{pwd} and username = #{username}")
    public List<User> findUserByUser(String username,String pwd);
}
